package com.iact.dao;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;

import com.iact.vo.Sysmanageroplog;

/**
 * A data access object (DAO) providing persistence and search support for
 * Sysmanageroplog entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see com.iact.vo.Sysmanageroplog
 * @author MyEclipse Persistence Tools
 */

public class SysmanageroplogDAO extends BaseHibernateDAO {
	private static final Log log = LogFactory.getLog(SysmanageroplogDAO.class);
	// property constants
	public static final String SYS_MANAGER = "sysManager";
	public static final String OPADRESS = "opadress";
	public static final String OPTYPE = "optype";
	public static final String OPCONTEXT = "opcontext";
	public static final String OPDATA = "opdata";

	public void save(Sysmanageroplog transientInstance) {
		log.debug("saving Sysmanageroplog instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(Sysmanageroplog persistentInstance) {
		log.debug("deleting Sysmanageroplog instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public Sysmanageroplog findById(java.lang.Long id) {
		log.debug("getting Sysmanageroplog instance with id: " + id);
		try {
			Sysmanageroplog instance = (Sysmanageroplog) getSession().get(
					"com.iact.vo.Sysmanageroplog", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(Sysmanageroplog instance) {
		log.debug("finding Sysmanageroplog instance by example");
		try {
			List results = getSession().createCriteria(
					"com.iact.vo.Sysmanageroplog")
					.add(Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding Sysmanageroplog instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from Sysmanageroplog as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findBySysManager(Object sysManager) {
		return findByProperty(SYS_MANAGER, sysManager);
	}

	public List findByOpadress(Object opadress) {
		return findByProperty(OPADRESS, opadress);
	}

	public List findByOptype(Object optype) {
		return findByProperty(OPTYPE, optype);
	}

	public List findByOpcontext(Object opcontext) {
		return findByProperty(OPCONTEXT, opcontext);
	}

	public List findByOpdata(Object opdata) {
		return findByProperty(OPDATA, opdata);
	}

	public List findAll() {
		log.debug("finding all Sysmanageroplog instances");
		try {
			String queryString = "from Sysmanageroplog";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public Sysmanageroplog merge(Sysmanageroplog detachedInstance) {
		log.debug("merging Sysmanageroplog instance");
		try {
			Sysmanageroplog result = (Sysmanageroplog) getSession().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(Sysmanageroplog instance) {
		log.debug("attaching dirty Sysmanageroplog instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Sysmanageroplog instance) {
		log.debug("attaching clean Sysmanageroplog instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}